package com.uniknow.app.action;

import java.util.ArrayList;
import java.util.HashMap;

import android.content.Context;

import com.uniknow.app.bin.TBCallLog;
import com.uniknow.app.bin.TBSMS;
import com.uniknow.app.manager.DatabaseHelper;
import com.uniknow.app.operate.BaseListener;

public class ActionAnalysis {
	private Context mContext;
	private ActionCalog acCalog;
	private ActionSMS acSMS;
	private ActionFriend acFriend;
	private int months = 10;//时间段的长短 10个月
	
	public ActionAnalysis(Context context){
		super();
		mContext = context;
		acCalog = new ActionCalog(mContext);
		acSMS = new ActionSMS(mContext);
		acFriend = new ActionFriend(mContext);
	}
	
	/**
	 * 猜一猜1
	 * @author lianjiao 
	 * @created 2013-11-27
	 */
	public void guess(){
		/*先求出通话记录和短信的发送的比例*/
		//DatabaseHelper.OpenDataBase(mContext);
		int countCalog = acCalog.GetCalogCount("",months,null);
		int countSms = acSMS.GetSMSCount("", months);
		int percentCalog = (int)(Math.round((Float.parseFloat(countCalog+"")/(countCalog+countSms))*100));
		int percentSms = (int)(Math.round((Float.parseFloat(countSms+"")/(countCalog+countSms))*100));
		System.out.println("countCalog = "+countCalog+" countSms = "+countSms);
		System.out.println("percentCalog = "+percentCalog+" percentSms = "+percentSms);
		/*一段时间内 短信频繁度逆序表*/
		ArrayList<TBCallLog> listCalog = acCalog.GetCalogListByParam(true, false, months);
		System.out.println("listCalog.size = "+listCalog.size());
		for(int i=0;i<10;i++){
			//System.out.println(listCalog.get(i).getName()+"--"+listCalog.get(i).getTel());
		}
		/*一段时间内 通话频繁度逆序表*/
		ArrayList<TBSMS> listSMS = acSMS.GetSMSListByParam(true, true, months);
		for(int i=0;i<10;i++){
			//System.out.println(listSMS.get(i).getName()+"--"+listSMS.get(i).getTel());
		}
		System.out.println("listSMS.size = "+listSMS.size());
		/*计算存储联系热度*/
		HashMap<String,Integer> mapCalog = new HashMap<String,Integer>();
		HashMap<String,Integer> mapSMS = new HashMap<String,Integer>();
		String mk;
		int mv;
		for(TBCallLog tbCalog:listCalog){
			mk = tbCalog.getTel();
			mv = tbCalog.getTimes()*percentCalog;
			mapCalog.put(mk,mv);
		}
		for(TBSMS tbSMS:listSMS){
			mk = tbSMS.getTel();
			mv = tbSMS.getTimes();
			mapSMS.put(mk,mv);
		}
		acFriend.SetHotValue(mapCalog);
		acFriend.SetHotValue(mapSMS);
		//新加的方法，不知道这里需要不需要关闭
		DatabaseHelper.clearHelper();
		//DatabaseHelper.CloseDataBase(mContext);
		
	}

}
